package sudroid.json;

import java.util.Iterator;

public class XML
{
  public static final Character AMP = new Character(38);
  public static final Character APOS = new Character(39);
  public static final Character BANG = new Character(33);
  public static final Character EQ = new Character(61);
  public static final Character GT = new Character(62);
  public static final Character LT = new Character(60);
  public static final Character QUEST = new Character(63);
  public static final Character QUOT = new Character(34);
  public static final Character SLASH = new Character(47);

  public static String escape(String paramString)
  {
    StringBuffer localStringBuffer1 = new StringBuffer();
    int i = 0;
    int j = paramString.length();
    if (i >= j)
      return localStringBuffer1.toString();
    char c = paramString.charAt(i);
    switch (c)
    {
    default:
      StringBuffer localStringBuffer2 = localStringBuffer1.append(c);
    case '&':
    case '<':
    case '>':
    case '"':
    }
    while (true)
    {
      i += 1;
      break;
      StringBuffer localStringBuffer3 = localStringBuffer1.append("&amp;");
      continue;
      StringBuffer localStringBuffer4 = localStringBuffer1.append("&lt;");
      continue;
      StringBuffer localStringBuffer5 = localStringBuffer1.append("&gt;");
      continue;
      StringBuffer localStringBuffer6 = localStringBuffer1.append("&quot;");
    }
  }

  public static void noSpace(String paramString)
    throws JSONException
  {
    int i = paramString.length();
    if (i == 0)
      throw new JSONException("Empty string.");
    int j = 0;
    while (true)
    {
      if (j >= i)
        return;
      if (Character.isWhitespace(paramString.charAt(j)))
      {
        String str = "'" + paramString + "' contains a space character.";
        throw new JSONException(str);
      }
      j += 1;
    }
  }

  private static boolean parse(XMLTokener paramXMLTokener, JSONObject paramJSONObject, String paramString)
    throws JSONException
  {
    Object localObject1 = paramXMLTokener.nextToken();
    Character localCharacter1 = BANG;
    int i;
    int j;
    if (localObject1 == localCharacter1)
    {
      i = paramXMLTokener.next();
      if (i == 45)
        if (paramXMLTokener.next() == 45)
        {
          boolean bool1 = paramXMLTokener.skipPast("-->");
          j = 0;
        }
    }
    while (true)
    {
      return j;
      paramXMLTokener.back();
      label56: int k = 1;
      label187: 
      while (true)
      {
        localObject1 = paramXMLTokener.nextMeta();
        if (localObject1 == null)
        {
          throw paramXMLTokener.syntaxError("Missing '>' after '<!'.");
          if (i != 91)
            break label56;
          if ((paramXMLTokener.nextToken().equals("CDATA")) && (paramXMLTokener.next() == 91))
          {
            localObject2 = paramXMLTokener.nextCDATA();
            if (((String)localObject2).length() > 0)
              JSONObject localJSONObject1 = paramJSONObject.accumulate("content", localObject2);
            j = 0;
            break;
          }
          throw paramXMLTokener.syntaxError("Expected 'CDATA['");
        }
        Character localCharacter2 = LT;
        if (localObject1 == localCharacter2)
          k += 1;
        while (true)
        {
          if (k > 0)
            break label187;
          j = 0;
          break;
          Character localCharacter3 = GT;
          if (localObject1 != localCharacter3)
            continue;
          k += -1;
        }
      }
      Character localCharacter4 = QUEST;
      if (localObject1 == localCharacter4)
      {
        boolean bool2 = paramXMLTokener.skipPast("?>");
        j = 0;
        continue;
      }
      Character localCharacter5 = SLASH;
      if (localObject1 != localCharacter5)
        break;
      localObject1 = paramXMLTokener.nextToken();
      if (paramString == null)
      {
        String str1 = "Mismatched close tag" + localObject1;
        throw paramXMLTokener.syntaxError(str1);
      }
      if (!localObject1.equals(paramString))
      {
        String str2 = "Mismatched " + paramString + " and " + localObject1;
        throw paramXMLTokener.syntaxError(str2);
      }
      Object localObject3 = paramXMLTokener.nextToken();
      Character localCharacter6 = GT;
      if (localObject3 != localCharacter6)
        throw paramXMLTokener.syntaxError("Misshaped close tag");
      j = 1;
    }
    if ((localObject1 instanceof Character))
      throw paramXMLTokener.syntaxError("Misshaped tag");
    String str3 = (String)localObject1;
    localObject1 = null;
    JSONObject localJSONObject2 = new JSONObject();
    label363: if (localObject1 == null);
    for (Object localObject2 = paramXMLTokener.nextToken(); ; localObject2 = localObject1)
    {
      if ((localObject2 instanceof String))
      {
        localObject2 = (String)localObject2;
        localObject1 = paramXMLTokener.nextToken();
        Character localCharacter7 = EQ;
        if (localObject1 == localCharacter7)
        {
          localObject1 = paramXMLTokener.nextToken();
          if (!(localObject1 instanceof String))
            throw paramXMLTokener.syntaxError("Missing value");
          Object localObject4 = JSONObject.stringToValue((String)localObject1);
          JSONObject localJSONObject3 = localJSONObject2.accumulate((String)localObject2, localObject4);
          localObject1 = null;
          break label363;
        }
        JSONObject localJSONObject4 = localJSONObject2.accumulate((String)localObject2, "");
        break label363;
      }
      Character localCharacter8 = SLASH;
      if (localObject2 == localCharacter8)
      {
        Object localObject5 = paramXMLTokener.nextToken();
        Character localCharacter9 = GT;
        if (localObject5 != localCharacter9)
          throw paramXMLTokener.syntaxError("Misshaped tag");
        JSONObject localJSONObject5 = paramJSONObject.accumulate(str3, localJSONObject2);
        j = 0;
        break;
      }
      Character localCharacter10 = GT;
      if (localObject2 == localCharacter10)
      {
        label615: Character localCharacter11;
        do
        {
          while (true)
          {
            localObject1 = paramXMLTokener.nextContent();
            if (localObject1 == null)
            {
              if (str3 != null)
              {
                String str4 = "Unclosed tag " + str3;
                throw paramXMLTokener.syntaxError(str4);
              }
              j = 0;
              break;
            }
            if (!(localObject1 instanceof String))
              break label615;
            localObject2 = (String)localObject1;
            if (((String)localObject2).length() <= 0)
              continue;
            Object localObject6 = JSONObject.stringToValue((String)localObject2);
            JSONObject localJSONObject6 = localJSONObject2.accumulate("content", localObject6);
          }
          localCharacter11 = LT;
        }
        while ((localObject1 != localCharacter11) || (!parse(paramXMLTokener, localJSONObject2, str3)));
        if (localJSONObject2.length() == 0)
          JSONObject localJSONObject7 = paramJSONObject.accumulate(str3, "");
        while (true)
        {
          j = 0;
          break;
          if ((localJSONObject2.length() == 1) && (localJSONObject2.opt("content") != null))
          {
            Object localObject7 = localJSONObject2.opt("content");
            JSONObject localJSONObject8 = paramJSONObject.accumulate(str3, localObject7);
            continue;
          }
          JSONObject localJSONObject9 = paramJSONObject.accumulate(str3, localJSONObject2);
        }
      }
      throw paramXMLTokener.syntaxError("Misshaped tag");
    }
  }

  public static JSONObject toJSONObject(String paramString)
    throws JSONException
  {
    JSONObject localJSONObject = new JSONObject();
    XMLTokener localXMLTokener = new XMLTokener(paramString);
    while (true)
    {
      if ((!localXMLTokener.more()) || (!localXMLTokener.skipPast("<")))
        return localJSONObject;
      boolean bool = parse(localXMLTokener, localJSONObject, null);
    }
  }

  public static String toString(Object paramObject)
    throws JSONException
  {
    return toString(paramObject, null);
  }

  public static String toString(Object paramObject, String paramString)
    throws JSONException
  {
    StringBuffer localStringBuffer1 = new StringBuffer();
    Object localObject2;
    label96: String str1;
    if ((paramObject instanceof JSONObject))
    {
      if (paramString != null)
      {
        StringBuffer localStringBuffer2 = localStringBuffer1.append(60);
        StringBuffer localStringBuffer3 = localStringBuffer1.append(paramString);
        StringBuffer localStringBuffer4 = localStringBuffer1.append(62);
      }
      JSONObject localJSONObject = (JSONObject)paramObject;
      localObject2 = localJSONObject.keys();
      if (!((Iterator)localObject2).hasNext())
      {
        if (paramString != null)
        {
          StringBuffer localStringBuffer5 = localStringBuffer1.append("</");
          StringBuffer localStringBuffer6 = localStringBuffer1.append(paramString);
          StringBuffer localStringBuffer7 = localStringBuffer1.append(62);
        }
        paramObject = localStringBuffer1.toString();
        return paramObject;
      }
      str1 = ((Iterator)localObject2).next().toString();
      paramObject = localJSONObject.opt(str1);
      if (paramObject != null)
        break label643;
    }
    label643: for (Object localObject4 = ""; ; localObject4 = paramObject)
    {
      if ((localObject4 instanceof String))
        String str2 = (String)localObject4;
      Object localObject3;
      while (true)
      {
        if (!str1.equals("content"))
          break label246;
        if (!(localObject4 instanceof JSONArray))
          break label225;
        localObject4 = (JSONArray)localObject4;
        localObject3 = ((JSONArray)localObject4).length();
        paramObject = 0;
        while (paramObject < localObject3)
        {
          if (paramObject > 0)
            StringBuffer localStringBuffer8 = localStringBuffer1.append(10);
          String str3 = escape(((JSONArray)localObject4).get(paramObject).toString());
          StringBuffer localStringBuffer9 = localStringBuffer1.append(str3);
          paramObject += 1;
        }
        break;
      }
      label225: String str4 = escape(localObject4.toString());
      StringBuffer localStringBuffer10 = localStringBuffer1.append(str4);
      break;
      label246: if ((localObject4 instanceof JSONArray))
      {
        localObject4 = (JSONArray)localObject4;
        Object localObject5 = ((JSONArray)localObject4).length();
        paramObject = 0;
        Object localObject6;
        if (paramObject < localObject5)
        {
          localObject6 = ((JSONArray)localObject4).get(paramObject);
          if (!(localObject6 instanceof JSONArray))
            break label362;
          StringBuffer localStringBuffer11 = localStringBuffer1.append(60);
          StringBuffer localStringBuffer12 = localStringBuffer1.append(localObject3);
          StringBuffer localStringBuffer13 = localStringBuffer1.append(62);
          String str5 = toString(localObject6);
          StringBuffer localStringBuffer14 = localStringBuffer1.append(str5);
          StringBuffer localStringBuffer15 = localStringBuffer1.append("</");
          StringBuffer localStringBuffer16 = localStringBuffer1.append(localObject3);
          StringBuffer localStringBuffer17 = localStringBuffer1.append(62);
        }
        while (true)
        {
          paramObject += 1;
          break label270;
          break;
          String str6 = toString(localObject6, localObject3);
          StringBuffer localStringBuffer18 = localStringBuffer1.append(str6);
        }
      }
      label270: label362: if (localObject4.equals(""))
      {
        StringBuffer localStringBuffer19 = localStringBuffer1.append(60);
        StringBuffer localStringBuffer20 = localStringBuffer1.append(localObject3);
        StringBuffer localStringBuffer21 = localStringBuffer1.append("/>");
        break;
      }
      String str7 = toString(localObject4, localObject3);
      StringBuffer localStringBuffer22 = localStringBuffer1.append(str7);
      break;
      if ((paramObject instanceof JSONArray))
      {
        localObject4 = (JSONArray)paramObject;
        Object localObject1 = ((JSONArray)localObject4).length();
        paramObject = 0;
        if (paramObject >= localObject1)
        {
          paramObject = localStringBuffer1.toString();
          break label96;
        }
        localObject3 = ((JSONArray)localObject4).opt(paramObject);
        if (paramString == null);
        for (localObject2 = "array"; ; localObject2 = paramString)
        {
          String str8 = toString(localObject3, (String)localObject2);
          StringBuffer localStringBuffer23 = localStringBuffer1.append(str8);
          paramObject += 1;
          break;
        }
      }
      if (paramObject == null);
      for (paramObject = "null"; ; paramObject = escape(paramObject.toString()))
      {
        if (paramString != null)
          break label568;
        paramObject = "\"" + paramObject + "\"";
        break;
      }
      label568: if (paramObject.length() == 0)
      {
        paramObject = "<" + paramString + "/>";
        break label96;
      }
      paramObject = "<" + paramString + ">" + paramObject + "</" + paramString + ">";
      break label96;
    }
  }
}

/* Location:           D:\Program Files\eclipse\apktool-r01-3\新浪微博\classes.dex.dex2jar.jar
 * Qualified Name:     sudroid.json.XML
 * JD-Core Version:    0.6.0
 */